﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using System.Threading;
using XNATweener;

namespace tactics
{
    public class AnimationManager
    {
        List<Tweener> tweens;
        List<Tweener> toRemove;
        List<Tweener> toAdd;

        public AnimationManager()
        {
            tweens = new List<Tweener>();
            toRemove = new List<Tweener>();
            toAdd = new List<Tweener>();
        }

        public void AddTween(Tweener tween)
        {
            tween.Ended += new Tweener.EndHandler(EndTween);
            toAdd.Add(tween);
        }

        public void Update(GameTime gameTime)
        {
            foreach (var t in toAdd)
            {
                tweens.Add(t);
            }
            toAdd.Clear();

            foreach (Tweener t in tweens)
            {
                t.Update(gameTime);
            }
            
            foreach (var t in toRemove)
            {
                tweens.Remove(t);
            }
            toRemove.Clear();
        }

        private void EndTween(Tweener ended)
        {
            toRemove.Add(ended);
        }
    }

 
}
